package com.yydm.serviceorder.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yydm.commonutils.JwtUtils;
import com.yydm.commonutils.R;
import com.yydm.serviceorder.entity.AutomobileOrder;
import com.yydm.serviceorder.service.IAutomobileOrderService;
import com.yydm.serviceorder.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yydm
 * @since 2022-07-14
 */
@RestController
@RequestMapping("/aaaa")
//@CrossOrigin
public class AutomobileOrderController {

    @Autowired
    private IAutomobileOrderService automobileOrderService;

    @PostMapping("/createOrder/{automobileId}")
    public R addOrder(@PathVariable String automobileId, HttpServletRequest request) {
//      创建订单,返回订单号
        String orderId = automobileOrderService.createOrder(automobileId, JwtUtils.getMemberIdByJwtToken(request));
        return R.ok().data("orderId", orderId);
    }

    //    根据id获取订单信息
    @GetMapping("/getOrderInfo/{orderId}")
    public R getOrderInfo(@PathVariable String orderId) {

        QueryWrapper<AutomobileOrder> wrapper = new QueryWrapper<>();
        wrapper.eq("order_id", orderId);
        AutomobileOrder one = automobileOrderService.getOne(wrapper);

        return R.ok().data("item", one);
    }

}
